package homework;

import java.util.ArrayList;
import java.util.List;

public class FilterApple {
    public static List<Apple> filterByWeight(List<Apple> datas, double weight){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(weight>=apple.getWeight()){
                result.add(apple);
            }
        }
        return result;
    }

    public static List<Apple> filterByType(List<Apple> datas, String type){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(type.equals(apple.getType())){
                result.add(apple);
            }
        }
        return result;
    }
    public static List<Apple> filterByColor(List<Apple> datas, String color){
        List<Apple> result=new ArrayList<>();
        for(Apple apple:datas){
            if(color.equals(apple.getColor())){
                result.add(apple);
            }
        }
        return result;
    }
    public interface Filter {
        boolean filter(Apple apple);
    }
    public static List<Apple>  filter(List<Apple> datas,Filter filter) {
        List<Apple> result = new ArrayList<>();
        for (Apple apple : datas) {
            if (filter.filter(apple)) {
                result.add(apple);
            }
        }
        return result;
    }


}
